#include "Application.h"
#include <QWidget>
#include <QVector>

#include "Common.h"

Application::Application(int argc, char **argv) : QApplication(argc,argv)
{
    mArgc = argc;
    mArgv = argv;
}

void mem_test(){
    sSharedMemory->CreateMem<QVector<int>>("v1");
    QVector<int>* v;
    sSharedMemory->GetMemWriteLock("v1", (void**)&v);
    v->append(1);
    v->append(2);
    v->append(3);
    sSharedMemory->UnlockMem("v1");


    sSharedMemory->CreateMem1<int,int>("num",999);
    const int* aa;
    sSharedMemory->GetMemReadLock("num", (const void**)&aa);
    sSharedMemory->UnlockMem("num");
    int b = *aa;


    sSharedMemory->DeleteMem<QVector<int>>("v1");


    QVector<int>* v1;
    MemError err = sSharedMemory->GetMemWriteLock("v1", (void**)&v1);
    //do somthing
    if(err == OK){
        sSharedMemory->UnlockMem("v1");
    }


}

bool Application::Init()
{
    QString pluginFolder = QApplication::applicationDirPath()+"/plugins";
    sPluginManager->PreLoadPlugin(pluginFolder);
    bool needLoad = sPluginManager->ChoosePlugin();
    if(needLoad){
        sPluginManager->LoadPlugin(mArgc, mArgv);
        sPluginManager->AfterLoadPlugin();
    }else{

    }

    return true;
}


